﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace AbyssCombatLogger 
{
    [Serializable]
    public enum ClassTypes
    {
        Unknown, Assassin, Barbarian, BearShaman, Conqueror, DarkTemplar, Demonologist,
        Guardian, HeraldOfXotli, Necromancer, PriestOfMitra, Ranger, TempestOfSet,
        Soldier, Priest, Rogue, Mage //class types
    }


    [Serializable]
    public class Player 
    {
        private string name = null;
        public string Name
        {
            get { return name; }
            set
            {
                if (value != null && value !="")
                {
                    string trimmed = value.Trim();
                    if (trimmed != "" && !trimmed.Contains(" ")) //right now provides no guarantee of uniqueness, but i will add a static list of all the Targets and thier names
                        name = trimmed;
                }
            }
        }

        protected static System.UInt32 playerCount = 0;

        protected static System.UInt32 nameLessPlayerCount = 0;
        
        public Player(string playerName)
        {
            ConstructByName(playerName);
        }
        public Pen CreatePen()
        {
            if (this.graphColor != Color.Empty)
            {
                penForCharts = new Pen(this.graphColor);
            }
            else
            {
                penForCharts = null;
            }
            return penForCharts;
        }
        public Brush CreateSolidBrush()
        {
            if (this.graphColor != Color.Empty)
            {
                brushForCharts = new SolidBrush(this.graphColor);
            }
            else
            {
                brushForCharts = null;
            }
            return brushForCharts;
        }
        public void CreatePenAndSolidBrush()
        {
            penForCharts = new Pen(this.graphColor);
            BrushForCharts = new SolidBrush(this.graphColor);
        }
        public Player(string playerName, bool lookupPlayer, TreeNode tnAssociated)
        {
            ConstructByName(playerName);

            AssociateTagOnNode(tnAssociated);
        }

        private void ConstructByName(string playerName)
        {
            playerCount++;
            ID = playerCount; //if lookupPlayer should lookup id by (string) name.

            if (playerName == null || playerName == "")
            {
                nameLessPlayerCount++;
                this.name = "Player" + nameLessPlayerCount;
            }
            else this.Name = playerName;
        }

        public void AssociateTagOnNode(TreeNode tnAssociated)
        {
            if (tnAssociated != null)
                tnAssociated.Tag = this;
        }

        public void LoadFromExistingPlayer()
        {
            //get data from a file ... or even better load the file first, copy it, close it, make a list 
            //and crossrefernce the data
        }

        private System.UInt32 ID = 0; //for cross referencing from data in files, and for sorting

        private ClassTypes classType;
        private float threatConstantRating = 1f;

        public float PercentHateModication
        {
            get { return (threatConstantRating - 1)*100f; }
            set { threatConstantRating = value / 100f + 1; }
        }

        public float ThreatRating
        {
            get { return threatConstantRating; }
            set
            {
                threatConstantRating = value;
            }
        }

        public Color graphColor = Color.Empty;
        
        public Color GraphColor
        {
            get { return graphColor; }
            set {
                if (value != Color.Empty)
                {
                    penForCharts = new Pen(value);
                    brushForCharts = new SolidBrush(value);
                    graphColor = value;
                }
            }
        }

        private string guild;

        public string Guild
        {
            get { return guild; }
            set { guild = value; }
        }
        [NonSerialized]
        public Pen penForCharts = null;

        public Pen PenForCharts
        {
            get
            {
                return penForCharts;
            }

            set { 
                penForCharts = value;
                graphColor = PenForCharts.Color;
            }
        }


        [NonSerialized]
        public Brush brushForCharts = null;

        public Brush BrushForCharts
        {
            get { return brushForCharts; }
            set { 
                brushForCharts = value;
            }
        }

        //public bool useGraphColor = false;

        public string ClassTypeToString()
        {
            return ClassTypeString(this.classType);
        }
        public static string ClassTypeString (ClassTypes classType)
        {
                switch (classType)
                {
                    case ClassTypes.Assassin:
                        return "Assassin";
                    case ClassTypes.Barbarian:
                        return "Barbarian";
                    case ClassTypes.BearShaman:
                        return "Bear Shaman";
                    case ClassTypes.Conqueror:
                        return "Conqueror";
                    case ClassTypes.DarkTemplar:
                        return "Dark Templar";
                    case ClassTypes.Demonologist:
                        return "Demonologist";
                    case ClassTypes.Guardian:
                        return "Guardian";
                    case ClassTypes.HeraldOfXotli:
                        return "Herald";
                    case ClassTypes.Necromancer:
                        return "Necromancer";
                    case ClassTypes.Ranger:
                        return "Ranger";
                    case ClassTypes.TempestOfSet:
                        return "Tempest Of Set";
                    case ClassTypes.Unknown:
                        return "<UnknownClass>";
                    case ClassTypes.Priest:
                        return "Priest";
                    case ClassTypes.Rogue:
                        return "Rogue";
                    case ClassTypes.Mage:
                        return "Mage";
                    case ClassTypes.Soldier:
                        return "Soldier";
                    default:
                        return "NEW CLASS!";
                }
       }
     
        public ClassTypes ClassType
        {
            get { return classType; }
            set { classType = value; }
        }
        public override string ToString()
        {
            if (name == null) return "";
            return name.ToString();
        }
    }
}
